package com.herui.ota.controller;

import com.herui.ota.config.ControllerNames;
import com.herui.ota.entity.DeviceOtaConfig;
import com.herui.ota.pojo.form.DeviceOtaConfigFilterForm;
import com.herui.ota.pojo.form.DeviceOtaHelpFilterForm;
import com.herui.ota.pojo.form.OtaSoftUpdateForm;
import com.herui.ota.service.DeviceOtaConfigService;
import com.herui.ota.service.iml.BaseService;
import com.mlnx.common.annotations.NeedLogin;
import com.mlnx.common.entity.Response;
import com.mlnx.common.form.PageForm;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.CurdBaseController;
import org.shan.spring.base.annotations.SysLog;
import org.shan.spring.mybatis.service.ICurdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = ControllerNames.OTAConfigName + "接口", tags = {ControllerNames.OTAConfigName + "接口"})
@SysLog(title = ControllerNames.OTAConfigName)
@RestController
@RequestMapping("/otaConfig")
public class OTAConfigController extends CurdBaseController<DeviceOtaConfig, DeviceOtaConfig, DeviceOtaConfig,
        DeviceOtaConfigFilterForm> {
    @Autowired
    private DeviceOtaConfigService service;

    @Override
    public ICurdService getService() {
        return service;
    }

    @Override
    public DeviceOtaConfig newInstance(Integer id) {
        DeviceOtaConfig soft = new DeviceOtaConfig();
        soft.setId(id);
        return soft;
    }

    @ApiOperation("导出excel列表")
    @GetMapping("/excel")
    public void getMqttParamById(PageForm pageForm, DeviceOtaConfigFilterForm filter, HttpServletResponse response) throws IllegalAccessException {
        BaseService baseService = (BaseService) service;
        baseService.pageExcel( pageForm, filter,response);
    }

    @NeedLogin
    @ApiOperation(
            value = "渠道批量打开",
            notes = ""
    )
    @PutMapping({"/mutilopen"})
    public Response channelOpen(@RequestBody  List<DeviceOtaConfig> deviceOtaConfigs) {
        service.channelOpen(deviceOtaConfigs);
        return this.result();
    }

    @NeedLogin
    @ApiOperation(
            value = "修改ota固件id",
            notes = ""
    )
    @PutMapping({"/changeOtaSoftId"})
    public Response channelOpen(@RequestBody OtaSoftUpdateForm otaSoftUpdateForm) {
        service.changeOtaSoftId(otaSoftUpdateForm);
        return this.result();
    }
}
